package com.eleadmin.order.biz.impl;

import com.eleadmin.damon.utils.results.BaseDao;
import com.eleadmin.damon.utils.results.PageResult2;

import com.eleadmin.damon.utils.utils.Utils;
import com.eleadmin.common.system.entity.User;
import com.eleadmin.order.biz.ContainerBillFeeBiz;
import com.eleadmin.order.entity.ContainerBill;
import com.eleadmin.order.entity.ContainerBillFee;
import com.eleadmin.common.core.web.JsonResult;
import com.eleadmin.order.param.ContainerBillParam;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SingleColumnRowMapper;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
 *
 * 数据层实现类
 * @author : Doman
 * @date : 2023-03-24 15:37:47
 * @version ：1.0
 */
@Repository
public class ContainerBillFeeBizImpl extends BaseDao implements ContainerBillFeeBiz {

    @Override
    public JsonResult list(PageResult2<T> page, ContainerBillFee containerBillFee, User loginUser) throws Exception {
        Map<String, String> map  = new HashMap<String, String>();
        RowMapper<ContainerBillFee> rm = new BeanPropertyRowMapper<ContainerBillFee>(ContainerBillFee.class);
        StringBuffer sql = new StringBuffer("select c.id,c.organization_id,c.bill_id");
        sql.append(",c.type,c.fee_name,c.price");
		sql.append(",c.fee_modules,c.fee_modules_order,c.invoicename,c.invoicestate");
//		sql.append(",ct.abbreviation invoicenameA");
		sql.append(",c.currency,c.exchange_rate");
		sql.append(",c.remark,c.create_time,c.create_user,c.update_time");
		sql.append(",c.update_user");
        sql.append(",sogzn.organization_name organizationName,suser.nickname createName,suser2.nickname updateName ");
        sql.append(" from chf_container_bill_fee c ");
//        sql.append(" inner join chf_customer ct on ct.name=c.invoicename ");
        sql.append(" inner join sys_user suser on suser.user_id=c.create_user ");
        sql.append(" left join sys_user suser2 on suser2.user_id=c.update_user ");
        sql.append(" inner join sys_organization sogzn on sogzn.organization_id=c.organization_id and sogzn.deleted=0 ");
        sql.append(" where c.deleted=0 and c.bill_id=:bill_id");
        map.put("bill_id", containerBillFee.getBillId());

        if(Utils.isNotEmpty(containerBillFee)){
    //			if(Utils.isNotEmpty(containerBillFee.getName())){
    //				sql.append(" and instr(c.name,:name)>0 ");
    //				map.put("name", containerBillFee.getName());
    //			}
          if(Utils.isNotEmpty(containerBillFee.getSort())&&Utils.isNotEmpty(containerBillFee.getOrder())){
              sql.append(" order by c."+containerBillFee.getSort()+" "+containerBillFee.getOrder());
          } else {
              loginUser.getRoles().stream().filter(role -> {
                  if (role.getRoleName().indexOf("调度") != -1) {
                      return true;
                  } else  {
                      return false;
                  }
              }).forEach(role -> {
                  map.put("dispatch_ret", "1");
              });
              if (map.get("dispatch_ret") != null) {
                  sql.append(" order by c.type asc,c.fee_modules_order, c.create_time desc");
              } else  {
                  sql.append(" order by c.type desc,c.fee_modules_order, c.create_time desc");
              }

          }
        }
        return jsonResult(getPageQueryList(page, sql.toString(), map, rm));
    }

    @Override
    public List<ContainerBillFee> list(ContainerBillFee containerBillFee, User loginUser) {
        Map<String, String> map  = new HashMap<String, String>();
        RowMapper<ContainerBillFee> rm = new BeanPropertyRowMapper<ContainerBillFee>(ContainerBillFee.class);
        StringBuffer sql = new StringBuffer("select c.id,c.organization_id,c.bill_id");
        sql.append(",c.type,c.fee_name,c.price");
		sql.append(",c.fee_modules,c.fee_modules_order,c.invoicename,c.invoicestate");
//        sql.append(",ct.abbreviation invoicenameA");
		sql.append(",c.currency,c.exchange_rate");
		sql.append(",c.remark,c.create_time,c.create_user,c.update_time");
		sql.append(",c.update_user");
        sql.append(",sogzn.organization_name organizationName,suser.nickname createName ");
        sql.append(" from chf_container_bill_fee c ");
//        sql.append(" inner join chf_customer ct on ct.name=c.invoicename ");
        sql.append(" inner join sys_user suser on suser.user_id=c.create_user ");
        sql.append(" inner join sys_organization sogzn on sogzn.organization_id=c.organization_id and sogzn.deleted=0 ");
        sql.append(" where c.deleted=0 and c.bill_id=:bill_id");
        map.put("bill_id", containerBillFee.getBillId());

        if(Utils.isNotEmpty(containerBillFee)){
            if(Utils.isNotEmpty(containerBillFee.getSort())&&Utils.isNotEmpty(containerBillFee.getOrder())){
                sql.append(" order by c."+containerBillFee.getSort()+" "+containerBillFee.getOrder());
            } else {
                sql.append(" order by c.type,c.fee_modules_order, c.create_time desc");
            }
        }
        getMapParameter(sql, map);
        return jdbcTemplate.query(sql.toString(),map, rm);
    }
    @Override
    public List<ContainerBillFee> listForCustomerExport(ContainerBillParam containerBillParam, User loginUser) {
        Map<String, String> map  = new HashMap<String, String>();
        RowMapper<ContainerBillFee> rm = new BeanPropertyRowMapper<ContainerBillFee>(ContainerBillFee.class);
//        select '应收' as type, fee_name, sum(if(type='应收',price, 0-price)) from  chf_container_bill_fee where bill_id=2270  GROUP BY fee_name , type
        StringBuffer sql = new StringBuffer("");
        sql.append("select '应收' as type,t.fee_name, sum(if(t.type='应收',t.price, 0-t.price)) price");
        sql.append(",t.fee_modules,t.invoicename,t.invoicestate");
        sql.append(",t.currency,t.exchange_rate from ");
        sql.append("(select c.type,c.price");
//		sql.append(",CASE WHEN REGEXP_INSTR(c.fee_name, '^提')  THEN '提箱'  WHEN REGEXP_INSTR(c.fee_name, '^进')  THEN '进港' ELSE c.fee_name END as fee_name");
        sql.append(",CASE WHEN fee_modules = '提箱'  THEN '提箱'  WHEN fee_modules = '进港'  THEN '进港' ELSE fee_name END fee_name ");
        sql.append(",c.fee_modules,c.invoicename,c.invoicestate");
        sql.append(",c.currency,c.exchange_rate");
        sql.append(" from chf_container_bill_fee c ");
        sql.append(" where c.deleted=0 and c.bill_id=:bill_id");
        map.put("bill_id", containerBillParam.getId());
        if (Utils.isNotEmpty(containerBillParam.getType())) {
            sql.append(" and c.type=:type ");
            map.put("type", containerBillParam.getType());
        }
        //甩手掌柜司机
        if (Utils.isNotEmpty(containerBillParam.getDriver())) {
            sql.append(" and c.invoicename=:invoicename ");
            map.put("invoicename", containerBillParam.getDriver());
        }
        //客户名称缩写
        if (Utils.isNotEmpty(containerBillParam.getCustomerAbbreviation())) {
            sql.append(" and c.invoicename=:invoicename ");
            map.put("invoicename", containerBillParam.getCustomerAbbreviation());
        }
        //车队名称缩写
        if (Utils.isNotEmpty(containerBillParam.getCarTeamAbbreviation())) {
            sql.append(" and c.invoicename=:invoicename ");
            map.put("invoicename", containerBillParam.getCarTeamAbbreviation());
        }
        if(Utils.isNotEmpty(containerBillParam.getApplyId()) && !containerBillParam.getApplyId().equals("0")){
            sql.append(" union all ");
            sql.append("select ");
            sql.append("f.type,f.price");
//            sql.append(",CASE WHEN REGEXP_INSTR(f.fee_name, '^提')  THEN '提箱'  WHEN REGEXP_INSTR(f.fee_name, '^进')  THEN '进港' ELSE f.fee_name END as fee_name");
            sql.append(",CASE WHEN fee_modules = '提箱'  THEN '提箱'  WHEN fee_modules = '进港'  THEN '进港' ELSE fee_name END fee_name ");
            sql.append(",f.fee_modules,f.invoicename,f.invoicestate");
            sql.append(",f.currency,f.exchange_rate");
            sql.append(" from chf_apply_customs_fee f ");
            sql.append(" where f.deleted=0 and f.apply_id=:apply_id");
            map.put("apply_id", containerBillParam.getApplyId());
            if (Utils.isNotEmpty(containerBillParam.getType())) {
                sql.append(" and f.type=:type ");
                map.put("type", containerBillParam.getType());
            }
            //甩手掌柜司机
            if (Utils.isNotEmpty(containerBillParam.getDriver())) {
                sql.append(" and f.invoicename=:invoicename ");
                map.put("invoicename", containerBillParam.getDriver());
            }
            //客户名称缩写
            if (Utils.isNotEmpty(containerBillParam.getCustomerAbbreviation())) {
                sql.append(" and f.invoicename=:invoicename ");
                map.put("invoicename", containerBillParam.getCustomerAbbreviation());
            }
            //车队名称缩写
            if (Utils.isNotEmpty(containerBillParam.getCarTeamAbbreviation())) {
                sql.append(" and f.invoicename=:invoicename ");
                map.put("invoicename", containerBillParam.getCarTeamAbbreviation());
            }
        }
        sql.append(" ) t ");
        sql.append(" group by type, t.fee_name,t.fee_modules,t.invoicename,t.invoicestate,t.currency,t.exchange_rate  ");
        getMapParameter(sql, map);
        return jdbcTemplate.query(sql.toString(),map, rm);
    }
    @Override
    public List<ContainerBillFee> listForExport(ContainerBillParam containerBillParam, User loginUser) {
        Map<String, String> map  = new HashMap<String, String>();
        RowMapper<ContainerBillFee> rm = new BeanPropertyRowMapper<ContainerBillFee>(ContainerBillFee.class);
        StringBuffer sql = new StringBuffer("select c.id");
        sql.append(",c.type,c.price");
//		sql.append(",CASE WHEN REGEXP_INSTR(c.fee_name, '^提')  THEN '提箱'  WHEN REGEXP_INSTR(c.fee_name, '^进')  THEN '进港' ELSE c.fee_name END as fee_name");
		sql.append(",CASE WHEN fee_modules = '提箱'  THEN '提箱'  WHEN fee_modules = '进港'  THEN '进港' ELSE fee_name END fee_name ");
		sql.append(",c.fee_modules,c.invoicename,c.invoicestate");
		sql.append(",c.currency,c.exchange_rate");
        sql.append(" from chf_container_bill_fee c ");
        sql.append(" where c.deleted=0 and c.bill_id=:bill_id");
        map.put("bill_id", containerBillParam.getId());
        if (Utils.isNotEmpty(containerBillParam.getType())) {
            sql.append(" and c.type=:type ");
            map.put("type", containerBillParam.getType());
        }
        //甩手掌柜司机
        if (Utils.isNotEmpty(containerBillParam.getDriver())) {
            sql.append(" and c.invoicename=:invoicename ");
            map.put("invoicename", containerBillParam.getDriver());
        }
        //客户名称缩写
        if (Utils.isNotEmpty(containerBillParam.getCustomerAbbreviation())) {
            sql.append(" and c.invoicename=:invoicename ");
            map.put("invoicename", containerBillParam.getCustomerAbbreviation());
        }
        //车队名称缩写
        if (Utils.isNotEmpty(containerBillParam.getCarTeamAbbreviation())) {
            sql.append(" and c.invoicename=:invoicename ");
            map.put("invoicename", containerBillParam.getCarTeamAbbreviation());
        }
        if(Utils.isNotEmpty(containerBillParam.getApplyId()) && !containerBillParam.getApplyId().equals("0")){
            sql.append(" union all ");
            sql.append("select f.id");
            sql.append(",f.type,f.price");
//            sql.append(",CASE WHEN REGEXP_INSTR(f.fee_name, '^提')  THEN '提箱'  WHEN REGEXP_INSTR(f.fee_name, '^进')  THEN '进港' ELSE f.fee_name END as fee_name");
            sql.append(",CASE WHEN fee_modules = '提箱'  THEN '提箱'  WHEN fee_modules = '进港'  THEN '进港' ELSE fee_name END fee_name ");
            sql.append(",f.fee_modules,f.invoicename,f.invoicestate");
            sql.append(",f.currency,f.exchange_rate");
            sql.append(" from chf_apply_customs_fee f ");
            sql.append(" where f.deleted=0 and f.apply_id=:apply_id");
            map.put("apply_id", containerBillParam.getApplyId());
            if (Utils.isNotEmpty(containerBillParam.getType())) {
                sql.append(" and f.type=:type ");
                map.put("type", containerBillParam.getType());
            }
            //甩手掌柜司机
            if (Utils.isNotEmpty(containerBillParam.getDriver())) {
                sql.append(" and f.invoicename=:invoicename ");
                map.put("invoicename", containerBillParam.getDriver());
            }
            //客户名称缩写
            if (Utils.isNotEmpty(containerBillParam.getCustomerAbbreviation())) {
                sql.append(" and f.invoicename=:invoicename ");
                map.put("invoicename", containerBillParam.getCustomerAbbreviation());
            }
            //车队名称缩写
            if (Utils.isNotEmpty(containerBillParam.getCarTeamAbbreviation())) {
                sql.append(" and f.invoicename=:invoicename ");
                map.put("invoicename", containerBillParam.getCarTeamAbbreviation());
            }
        }
        getMapParameter(sql, map);
        return jdbcTemplate.query(sql.toString(),map, rm);
    }

    @Override
    public List<String> feeNames(ContainerBill containerBill, User loginUser) {
        Map<String, Object> map = new HashMap<String, Object>();
        RowMapper<String> rm = new SingleColumnRowMapper<String>(String.class);
        StringBuffer sql = new StringBuffer("select distinct ");
        sql.append(" CASE WHEN REGEXP_INSTR(bf.fee_name, '^提')  THEN '提箱'  WHEN REGEXP_INSTR(bf.fee_name, '^进')  THEN '进港' ELSE bf.fee_name END as fee_name");
        sql.append(" from chf_container_bill_fee bf ");
        sql.append(" inner join chf_container_bill b on b.id=bf.bill_id and b.deleted=0 ");
//        sql.append(" and b.state='结单' ");
        sql.append(" where bf.deleted=0 ");
        if (Utils.isNotEmpty(containerBill)) {
            if (Utils.isNotEmpty(containerBill.getDate1())) {
                sql.append(" and b.factory_pack_date>= :date1 ");
                map.put("date1", containerBill.getDate1());
            }
            if (Utils.isNotEmpty(containerBill.getDate2())) {
                sql.append(" and b.factory_pack_date<=:date2 ");
                map.put("date2", containerBill.getDate2());
            }
            if (Utils.isNotEmpty(containerBill.getCustomer())) {
                sql.append(" and b.customer=:customer ");
                map.put("customer", containerBill.getCustomer());
            }
            //甩手掌柜司机
            if (Utils.isNotEmpty(containerBill.getDriver())) {
                sql.append(" and bf.invoicename=:invoicename ");
                map.put("invoicename", containerBill.getDriver());
            }
            if (Utils.isNotEmpty(containerBill.getType())) {
                sql.append(" and bf.type=:type ");
                map.put("type", containerBill.getType());
            }
        }
        sql.append(" union ");
        sql.append(" select distinct ");
        sql.append(" CASE WHEN REGEXP_INSTR(af.fee_name, '^提')  THEN '提箱'  WHEN REGEXP_INSTR(af.fee_name, '^进')  THEN '进港' ELSE af.fee_name END as fee_name");
        sql.append(" from chf_apply_customs_fee af ");
        sql.append(" inner join chf_contain_ocean_apply oa on oa.apply_id=af.apply_id ");
        sql.append(" inner join chf_container_bill b2 on b2.id=oa.containBill_id and b2.deleted=0 ");
//        sql.append(" and b2.state='结单' ");
        sql.append(" where af.deleted=0 ");
        if (Utils.isNotEmpty(containerBill)) {
            if (Utils.isNotEmpty(containerBill.getDate1())) {
                sql.append(" and b2.factory_pack_date>= :date1 ");
                map.put("date1", containerBill.getDate1());
            }
            if (Utils.isNotEmpty(containerBill.getDate2())) {
                sql.append(" and b2.factory_pack_date<=:date2 ");
                map.put("date2", containerBill.getDate2());
            }
            if (Utils.isNotEmpty(containerBill.getCustomer())) {
                sql.append(" and b2.customer=:customer ");
                map.put("customer", containerBill.getCustomer());
            }
            //甩手掌柜司机
            if (Utils.isNotEmpty(containerBill.getDriver())) {
                sql.append(" and af.invoicename=:invoicename ");
                map.put("invoicename", containerBill.getDriver());
            }
            if (Utils.isNotEmpty(containerBill.getType())) {
                sql.append(" and af.type=:type ");
                map.put("type", containerBill.getType());
            }
        }
        getMapParameter(sql, null);
        return jdbcTemplate.query(sql.toString(), map, rm);
    }

    @Override
    public List<String> feeNamesForCustomer(ContainerBill containerBill, User loginUser) {
        Map<String, Object> map = new HashMap<String, Object>();
        RowMapper<String> rm = new SingleColumnRowMapper<String>(String.class);
        StringBuffer sql = new StringBuffer("select distinct ");
        sql.append(" CASE WHEN REGEXP_INSTR(bf.fee_name, '^提')  THEN '提箱'  WHEN REGEXP_INSTR(bf.fee_name, '^进')  THEN '进港' ELSE bf.fee_name END as fee_name");
        sql.append(" from chf_container_bill_fee bf ");
        sql.append(" inner join chf_container_bill b on b.id=bf.bill_id and b.deleted=0 ");
//        sql.append(" and b.state='结单' ");
        sql.append(" where bf.deleted=0 ");
        if (Utils.isNotEmpty(containerBill)) {
            if (Utils.isNotEmpty(containerBill.getDate1())) {
                sql.append(" and b.factory_pack_date>= :date1 ");
                map.put("date1", containerBill.getDate1());
            }
            if (Utils.isNotEmpty(containerBill.getDate2())) {
                sql.append(" and b.factory_pack_date<=:date2 ");
                map.put("date2", containerBill.getDate2());
            }
            //甩手掌柜客户
            if (Utils.isNotEmpty(containerBill.getCustomerAbbreviation())) {
                sql.append(" and bf.invoicename=:invoicename ");
                map.put("invoicename", containerBill.getCustomerAbbreviation());
            }
            //甩手掌柜司机
            if (Utils.isNotEmpty(containerBill.getDriver())) {
                sql.append(" and bf.invoicename=:invoicename ");
                map.put("invoicename", containerBill.getDriver());
            }
//            if (Utils.isNotEmpty(containerBill.getType())) {
//                sql.append(" and bf.type=:type ");
//                map.put("type", containerBill.getType());
//            }
        }
        sql.append(" union ");
        sql.append(" select distinct ");
        sql.append(" CASE WHEN REGEXP_INSTR(af.fee_name, '^提')  THEN '提箱'  WHEN REGEXP_INSTR(af.fee_name, '^进')  THEN '进港' ELSE af.fee_name END as fee_name");
        sql.append(" from chf_apply_customs_fee af ");
        sql.append(" inner join chf_contain_ocean_apply oa on oa.apply_id=af.apply_id ");
        sql.append(" inner join chf_container_bill b2 on b2.id=oa.containBill_id and b2.deleted=0 ");
//        sql.append(" and b2.state='结单' ");
        sql.append(" where af.deleted=0 ");
        if (Utils.isNotEmpty(containerBill)) {
            if (Utils.isNotEmpty(containerBill.getDate1())) {
                sql.append(" and b2.factory_pack_date>= :date1 ");
                map.put("date1", containerBill.getDate1());
            }
            if (Utils.isNotEmpty(containerBill.getDate2())) {
                sql.append(" and b2.factory_pack_date<=:date2 ");
                map.put("date2", containerBill.getDate2());
            }
            //甩手掌柜客户
            if (Utils.isNotEmpty(containerBill.getCustomerAbbreviation())) {
                sql.append(" and af.invoicename=:invoicename ");
                map.put("invoicename", containerBill.getCustomerAbbreviation());
            }
            //甩手掌柜司机
            if (Utils.isNotEmpty(containerBill.getDriver())) {
                sql.append(" and af.invoicename=:invoicename ");
                map.put("invoicename", containerBill.getDriver());
            }
//            if (Utils.isNotEmpty(containerBill.getType())) {
//                sql.append(" and af.type=:type ");
//                map.put("type", containerBill.getType());
//            }
        }
        getMapParameter(sql, null);
        return jdbcTemplate.query(sql.toString(), map, rm);
    }

    @Override
    public ContainerBillFee getById(String id) {
        RowMapper<ContainerBillFee> rm = new BeanPropertyRowMapper<ContainerBillFee>(ContainerBillFee.class);
        Map<String, String> map  = new HashMap<String, String>();
        StringBuffer sql = new StringBuffer("select c.id,c.organization_id,c.bill_id");
        sql.append(",c.type,c.fee_name,c.price");
		sql.append(",c.fee_modules,c.fee_modules_order,c.invoicename,c.invoicestate");
		sql.append(",c.currency,c.exchange_rate");
		sql.append(",c.remark,c.create_time,c.create_user,c.update_time");
		sql.append(",c.update_user");
        sql.append(",sogzn.organization_name organizationName,suser.nickname createName ");
        sql.append(" from chf_container_bill_fee c ");
        sql.append(" inner join sys_user suser on suser.user_id=c.create_user ");
        sql.append(" inner join sys_organization sogzn on sogzn.organization_id=c.organization_id and sogzn.deleted=0 ");
        sql.append(" where c.deleted=0 and c.id=:id ");
        map.put("id", id);
        getMapParameter(sql, map);
        return jdbcTemplate.queryForObject(sql.toString(), map, rm);
    }

    public String getOrder(String feeModulesOrder) {
        if(feeModulesOrder.equals("运费")) { return "100"; }
        if(feeModulesOrder.equals("提箱")) { return "200"; }
        if(feeModulesOrder.equals("进港")) { return "300"; }
        if(feeModulesOrder.equals("其他")) { return "400"; }
        if(feeModulesOrder.equals("单项")) { return "500"; }
        if(feeModulesOrder.equals("采购")) { return "600"; }
        if(feeModulesOrder.equals("报关费")) { return "700"; }
        if(feeModulesOrder.equals("易港通")) { return "800"; }
        if(feeModulesOrder.equals("财务报销")) { return "900"; }
        return "1";
    }

    @Override
    public boolean save(ContainerBillFee containerBillFee, User loginUser) {
        Map<String, String> map  = new HashMap<String, String>();
        StringBuffer sql =new StringBuffer("insert into chf_container_bill_fee (");
        sql.append("organization_id,bill_id,type,fee_name");
		sql.append(",price,fee_modules,fee_modules_order,invoicename");
		sql.append(",invoicestate,currency,exchange_rate");
		sql.append(",remark,create_user,create_time) values ( ");
        sql.append(":organization_id,:bill_id,:type,:fee_name");
		sql.append(",:price,:fee_modules,:fee_modules_order,:invoicename");
		sql.append(",:invoicestate,:currency,:exchange_rate");
		sql.append(",:remark,:create_user,now())");
        map.put("organization_id", loginUser.getOrganizationId() + "");
        map.put("bill_id", containerBillFee.getBillId());
        map.put("type", containerBillFee.getType());
        map.put("fee_name", containerBillFee.getFeeName());
        map.put("price", containerBillFee.getPrice());
        map.put("fee_modules", containerBillFee.getFeeModules());
        map.put("fee_modules_order", getOrder(containerBillFee.getFeeModules()));
        map.put("invoicename", containerBillFee.getInvoicename());
        map.put("invoicestate", containerBillFee.getInvoicestate());
        map.put("currency", containerBillFee.getCurrency());
        map.put("exchange_rate", containerBillFee.getExchangeRate());
        map.put("remark", containerBillFee.getRemark());
        map.put("create_user", loginUser.getUserId() + "");
        getMapParameter(sql, map);
        int count = jdbcTemplate.update(sql.toString(), map);
        return count > 0;
    }

    @Override
    public boolean update(ContainerBillFee containerBillFee, User loginUser) {
        Map<String, String> map  = new HashMap<String, String>();
        StringBuffer sql =new StringBuffer("update chf_container_bill_fee set ");
        sql.append("bill_id=:bill_id,type=:type,fee_name=:fee_name ");
		sql.append(",price=:price,fee_modules=:fee_modules,fee_modules_order=:fee_modules_order ");
		sql.append(",invoicename=:invoicename,invoicestate=:invoicestate ");
		sql.append(",currency=:currency,exchange_rate=:exchange_rate ");
		sql.append(",remark=:remark,update_time=now() ");
		sql.append(",update_user=:update_user where id=:id ");
        map.put("bill_id", containerBillFee.getBillId());
        map.put("type", containerBillFee.getType());
        map.put("fee_name", containerBillFee.getFeeName());
        map.put("price", containerBillFee.getPrice());
        map.put("fee_modules", containerBillFee.getFeeModules());
        map.put("fee_modules_order", getOrder(containerBillFee.getFeeModules()));
        map.put("invoicename", containerBillFee.getInvoicename());
        map.put("invoicestate", containerBillFee.getInvoicestate());
        map.put("currency", containerBillFee.getCurrency());
        map.put("exchange_rate", containerBillFee.getExchangeRate());
        map.put("remark", containerBillFee.getRemark());
        map.put("update_user", loginUser.getUserId() + "");
        map.put("id", containerBillFee.getId());
        getMapParameter(sql, map);
        int count = jdbcTemplate.update(sql.toString(), map);
        return count > 0;
    }

    @Override
    public boolean remove(String id, User loginUser) {
        int count = 0;
        Map<String, String> map = null;
        if(id.length()>0){
            for(String id1 : id.split(",")){
                map  = new HashMap<String, String>();
                if(id1==null || id1.equals("")){ break; }
                StringBuffer sql =new StringBuffer("update chf_container_bill_fee set deleted=1" +
                    ",update_user=:update_user, update_time=now() "
                    + " where id =:id ");
                map.put("update_user", loginUser.getUserId() + "");
                map.put("id", id1);
                getMapParameter(sql, map);
                count = jdbcTemplate.update(sql.toString(),map);
            }
        }
        return count > 0;
    }


}
